package com.wch.clientdemo.module.base.network;

import android.content.Context;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;

/**
 * 
 * @author WanChengHe
 * @Date 20181115
 * Volley队列
 * 创建Volley数据池实例
 * 采用单例
 */
public class VolleyQueueController {

	private static VolleyQueueController controller;
	
	/**
	 * Volley请求队列
	 */
	private RequestQueue mRequestQueue;
	
	/**
	 * 请求对象
	 */
	private Context mContext;

	public VolleyQueueController(Context context) {
		mContext = context;
		mRequestQueue = getRequestQueue();
	}
	
	/**
	 * 单例模式，获取Volley实例
	 * @param context
	 * @return
	 */
	public static VolleyQueueController getInstance(Context context){
		if(null == controller){
			synchronized (VolleyQueueController.class) {
				if(null == controller){
					controller = new VolleyQueueController(context);
				}
			}
		}
		return controller;		
	}
	
	/**
	 * 获取Volley请求队列
	 * @return
	 */
	public RequestQueue getRequestQueue(){
		if(null == mRequestQueue){
			try {
				mRequestQueue = Volley.newRequestQueue(mContext.getApplicationContext());
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return mRequestQueue;	
	}
	
	
	
}
